﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Zhp.Common.Helper
{
    public static class AppHelper
    {
        /// <summary>
        /// 配置对象
        /// </summary>
        public static IConfiguration Configuration;

        /// <summary>
        /// 获取Web主机环境，如，是否是开发环境，生产环境等
        /// </summary>
        public static IWebHostEnvironment WebHostEnvironment;

        /// <summary>
        /// 应用服务
        /// </summary>
        public static IServiceCollection ServiceCollection;

        /// <summary>
        /// 记录应用程序配置文件和环境变量，方便后面使用，这个调用的位置不能往后移
        /// </summary>
        /// <param name="builder"></param>
        public static void ConfigureApplication(this WebApplicationBuilder builder)
        {
            Configuration = builder.Configuration;
            WebHostEnvironment = builder.Environment;
            ServiceCollection = builder.Services;

            ConsoleHelper.WriteLine($"运行程序: {WebHostEnvironment.ApplicationName}", ConsoleColor.Green);
        }
    }
}
